package dao;

import bean.Student;
import org.apache.ibatis.session.SqlSession;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.Random;

public class GetName {

    public static String  selectById() {          //查询指定ID
        ApplicationContext context = new ClassPathXmlApplicationContext("spring.xml");
        SqlSession sqlSession =(SqlSession) context.getBean("sqlSession");
        StudentMapper studentMapper=sqlSession.getMapper(StudentMapper.class);
        Random rand = new Random();
        int id=rand.nextInt(6);
        Student student=studentMapper.selectById(id);
        return student.getName();
    }
    public static void randomGroup(){
        int [] a = new int[6];

        for(int i = 0;i<a.length;i++){
            a[i]=(int)(Math.random()*10);
            for(int j = 0;j<i;j++){
                if(a[j]==a[i]){
                    i--;
                }
            }
        }

        for(int i = 0;i<a.length;i++){
            System.out.println(a[i]);
        }
    }
}
